
/*
 *  Copyright t lefering, David Given
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  These are the four essential freedoms with GNU GPL software:
 *  1: freedom to run the program, for any purpose
 *  2: freedom to study how the program works, and change it to make it do what you wish
 *  3: freedom to redistribute copies to help your Free Software friends
 *  4: freedom to distribute copies of your modified versions to your Free Software friends
 *   ,           ,
 *  /             \
 * ((__-^^-,-^^-__))
 * `-_---'  `---_-'
 *  `--|o`   'o|--'
 *      \  `  /
 *       ): :(
 *       :o_o:
 *        "-"
 */

#ifndef AVL_H
#define AVL_H 1

struct avlnode {
	int magic;
	void *data;
	struct avlnode *subtree[2];
	int balance;
};

typedef struct avlnode *avltree_t;

/* Various callbacks */
typedef int (*avl_comparison_cb_t)(const void *, const void *);
typedef void (*avl_item_cb_t)(void *);

/* Prototypes */
extern void *avl_search(avltree_t root, avl_comparison_cb_t comparefunc, void *target, int cmp);
extern void *avl_insert(avltree_t * rootp, avl_comparison_cb_t comparefunc, void *item, int *change);
extern void *avl_delete(avltree_t * rootp, avl_comparison_cb_t comparefunc, void *item, int *change, int cmp);
extern void avl_nuke(avltree_t root, avl_item_cb_t deletefunc);
extern int avl_validate(avltree_t this, avl_comparison_cb_t comparefunc);
extern void avl_traverse(avltree_t node, avl_item_cb_t displayfunc);

/* Node recognition magic number */
#define AVLTREE_MAGIC (0x11AA2233)

/* Prototypes */

extern void avl_dump(struct avlnode *node, avl_item_cb_t displayfunc, int level);

#endif

/* end */
